<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="lg" title="平台公告详情" hide-footer scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题</label>
                    <div class="col-lg-6">
                        <input class="form-control" type="text" maxlength="120" disabled v-model="noticeForm.title" placeholder="请输入">
                    </div>
                </div>
                <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">内&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;容</label>
                    <div class="col-lg-6">
                        <textarea class="form-control" maxlength="800" disabled v-model="noticeForm.content" placeholder="请输入"></textarea>
                    </div>
                </div>
                <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态</label>
                    <div class="col-lg-2">
                        <el-select v-model="noticeForm.state" disabled placeholder="请选择">
                            <el-option value="">请选择</el-option>
                            <el-option
                                v-for="item in [{value:'0',label:'初稿'},{value:'1',label:'审核提交'}]"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">基本附件</label>
                    <div class="col-lg-2">
                        <FileWidget @change="setFileUpload"  :fileOpt="fileOpt"></FileWidget>
                    </div>
                </div>
                <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">其它附件</label>
                    <div class="col-lg-2">
                        <FileWidget @change="setFileUpload"  :fileOpt="fileOpt1"></FileWidget>
                    </div>
                </div>
                <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">创建&nbsp;&nbsp;人</label>
                    <div class="col-lg-2">
                        <input class="form-control" v-model="noticeForm.createBy" disabled>
                    </div>
                </div>
                <div class="form-group m-form__group row">
                    <label class="col-lg-2 col-form-label">创建时间</label>
                    <div class="col-lg-4">
                        <input class="form-control" v-model="noticeForm.createTime" disabled>
                    </div>
                </div>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
            
        </template>
    </b-modal>
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import FileWidget from "@/components/file-widget.vue";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            fileOpt:{delete:false,upload:false,field:"attachmentId",value:""}, //用于传递参数 目的回调setFileUpload时能知道是哪个字段要设置值
            fileOpt1:{delete:false,upload:false,field:"attachmentId_",value:""}, //用于传递参数 目的回调setFileUpload时能知道是哪个字段要设置值
            noticeForm: {
                title: "",
                content: "",
                state:"",
                attachmentId:"",
                attachmentId_:"",
                createBy:'',
                createTime:"",

            }
        }
    },
    components: {
        FileWidget,
    },
    watch: {
    },
    mounted() {

    },
    methods: {        
        showModal(id) {
            this.restForm();
            this.$refs['my-modal'].show();
            this.getDetail(id);
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        restForm() {
            //重置
            Object.assign(this.$data.noticeForm, this.$options.data().noticeForm);
        },
        setFileUpload(res,callData){//回调设置值
            let jsonID = res.data.jsonID;           
            let field = callData.field;
            if(field === 'attachmentId'){                
                if(jsonID !== 0){        
                    this.noticeForm.attachmentId = jsonID;
                }
            }
            if(field === 'attachmentId_'){    
                 if(jsonID !== 0){                    
                    this.noticeForm.attachmentId_ = jsonID;
                }
            }
        },
        getDetail(id){
            apiUtil.get(process.env.VUE_APP_SYS_API+"/xtNotice/get/"+id).then(({ data }) => {
                this.noticeForm = data.data; 
                this.fileOpt.value = this.noticeForm.attachmentId;
                this.fileOpt1.value = this.noticeForm.attachmentId_;
            });
        },
    }
}
</script>